In many hydrocarbon well applications, a wellbore is drilled into a desired hydrocarbon-bearing formation. The drilling may be performed by cutting elements of a drilling tool forming part of a bottom hole assembly located in a drill string. When drilling deviated wellbores, the direction of drilling may be controlled by a steering system, such as a rotary steerable system. Electronics are disposed in a rotary steerable system control unit or in a measurement-while-drilling tool sensor package and may include several sensors used to measure the trajectory and attitude of the drilling tool at a given point in space. At least some of the sensors comprise magnetometers which are sensitive to the Earth's magnetic field and also to external magnetic influences, including metal above and below the sensors in the bottom hole assembly. The magnetic interference from drill string influences is calculated prior to the drilling job and an estimated error is determined. The estimated error may be reduced by providing a large distance between the drill bit and the magnetometer sensors. However, the large distance limits the type and accuracy of the data which may be obtained.